package tests;

import java.io.FileReader;
import java.io.IOException;
import java.util.Random;

import weka.classifiers.Evaluation;
import weka.classifiers.functions.MultilayerPerceptron;
import weka.core.Instances;

public class ThreadTestMlp implements Runnable {

	private static final int INDEX_OF_CLASS = 3;
	private static final int NUMBER_OF_FOLDERS = 5;
	
	private String input;
	private String quantidadeNeuronios;
	private double learningRate;
	private double momentum;
	private int numEpochs;
	
	public ThreadTestMlp(String input, String quantidadeNeuronios, double learningRate, double momentum, int numEpochs) {

		this.input = input;
		this.quantidadeNeuronios = quantidadeNeuronios;
		this.learningRate = learningRate;
		this.momentum = momentum;
		this.numEpochs = numEpochs;
	
	}

	@Override
	public void run() {
		
		MultilayerPerceptron mlp = new MultilayerPerceptron();
		mlp.setHiddenLayers(quantidadeNeuronios);
		mlp.setLearningRate(learningRate);
		mlp.setMomentum(momentum);
		mlp.setTrainingTime(numEpochs);

		
		try {
			
			FileReader reader = new FileReader("arffs/oneIndexByContinent/"+ input + ".arff");

			Instances allInstances;
			allInstances = new Instances(reader);
			allInstances.setClassIndex(INDEX_OF_CLASS);

			Evaluation evaluation = new Evaluation(allInstances);
			evaluation.crossValidateModel(mlp, allInstances, NUMBER_OF_FOLDERS, new Random());
			
			System.out.println(input + "\t" + quantidadeNeuronios + "\t" + learningRate + "\t" + momentum + "\t" + numEpochs + "\t" + (evaluation.pctCorrect()));
		
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}

	
		
	}

}
